/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author owner
 */
public class DBConn
    {

    private Connection connection;

    public DBConn(String server)
    {
        String url = "jdbc:jtds:sqlserver://"+server+":1433;"
                + "databaseName=service;domain=CAMPUS;";
        try {
            //load database driver
            Class.forName("net.sourceforge.jtds.jdbc.Driver");

            //establish connection to database
            connection = DriverManager.getConnection(url, LogIn.USERNAME, LogIn.PASSWORD);
        }
        //Catch cases
        //Driver not found
        catch (ClassNotFoundException e) {System.err.println("Error loading driver: " + e);}
        //Unable to connect (failed login)
        catch (SQLException e) {System.err.println("Error getting connection: " + e);}
        //Some other error
        catch (Exception e) {System.out.println("Some other error: " + e);}
    }
    public DBConn()
    {
        this("CSSADEV");
    }

    public Connection getConnection() {
        return connection;
    }
}
